﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Comukrte;

namespace Comukrte.Controllers
{ 
    public class AreasController : Controller
    {
        private comukrteEntities db = new comukrteEntities();

        //
        // GET: /Areas/
        [Authorize(Roles = "Administrador")]
        public ViewResult Index()
        {
            return View(db.tblAreas.ToList());
        }

        //
        // GET: /Areas/Details/5
        [Authorize(Roles = "Administrador")]
        public ViewResult Details(int id)
        {
            tblAreas tblareas = db.tblAreas.Find(id);
            return View(tblareas);
        }

        //
        // GET: /Areas/Create
        [Authorize(Roles = "Administrador")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Areas/Create
        [Authorize(Roles = "Administrador")]
        [HttpPost]
        public ActionResult Create(tblAreas tblareas)
        {
            if (ModelState.IsValid)
            {
                db.tblAreas.Add(tblareas);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(tblareas);
        }
        
        //
        // GET: /Areas/Edit/5
 [Authorize(Roles = "Administrador")]
        public ActionResult Edit(int id)
        {
            tblAreas tblareas = db.tblAreas.Find(id);
            return View(tblareas);
        }

        //
        // POST: /Areas/Edit/5
        [Authorize(Roles = "Administrador")]
        [HttpPost]
        public ActionResult Edit(tblAreas tblareas)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tblareas).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tblareas);
        }

        //
        // GET: /Areas/Delete/5
 [Authorize(Roles = "Administrador")]
        public ActionResult Delete(int id)
        {
            tblAreas tblareas = db.tblAreas.Find(id);
            return View(tblareas);
        }

        //
        // POST: /Areas/Delete/5
        [Authorize(Roles = "Administrador")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            tblAreas tblareas = db.tblAreas.Find(id);
            db.tblAreas.Remove(tblareas);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}